import sys
import os

def is_roman_numeral(s):
    # 检查是否为罗马数字
    roman_numerals = {'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x'}
    return s.lower() in roman_numerals

def format_filename(filename):
    # 将首字母大写
    words = filename.split('-')
    formatted_words = []
    
    for i, word in enumerate(words):
        # 检查是否为罗马数字
        if is_roman_numeral(word):
            formatted_word = word.upper()
        else:
            # 将每个单词的首字母大写
            formatted_word = word.capitalize()
        formatted_words.append(formatted_word)
    
    # 用下划线连接所有单词
    return '_'.join(formatted_words)

if __name__ == '__main__':
    file_name = 'test'
    folder_name = ''
    
    try:
        file_name = sys.argv[1]
        folder_name = sys.argv[2]
    except IndexError:
        print("Usage: python create_empty_file.py [filename] [foldername]")
        sys.exit(1)

    # 格式化文件名
    if '-' in file_name:
        file_name = format_filename(file_name)
    
    # 如果提供了文件夹名，则创建文件夹
    if folder_name:
        if not os.path.exists(f"python/{folder_name}"):
            os.makedirs(f"python/{folder_name}")
        if not os.path.exists(f"java/{folder_name}"):
            os.makedirs(f"java/{folder_name}")
        
        print(f"Creating {file_name} in java/{folder_name} and python/{folder_name} ...")
        with open(f"python/{folder_name}/{file_name}.py", 'w'):
            pass
        with open(f"java/{folder_name}/{file_name}.java", 'w'):
            pass
    else:
        print(f"Creating {file_name} in java and python dir...")
        with open(f"python/{file_name}.py", 'w'):
            pass
        with open(f"java/{file_name}.java", 'w'):
            pass
    
    print("Done!")